<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>带状疱疹神经痛风险自测</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        max-width: 600px;
        margin: 0 auto;
        padding: 20px;
      }
      .question {
        margin-bottom: 30px;
      }
      button {
        display: block;
        margin: 10px 0;
        padding: 10px;
        width: 100%;
      }
      #report {
        display: none;
        margin-top: 30px;
        padding: 20px;
        border: 1px solid #ccc;
      }
      .risk-low {
        background-color: #d4edda;
      }
      .risk-medium {
        background-color: #fff3cd;
      }
      .risk-high {
        background-color: #f8d7da;
      }
    </style>
  </head>
  <body>
    <h1>带状疱疹神经痛风险自测</h1>
    <div id="pain-test">
      <!-- 问题1：年龄 -->
      <div class="question">
        <h3>您的年龄是？</h3>
        <button data-value="0">＜30岁</button>
        <button data-value="1">30-49岁</button>
        <button data-value="2">50-59岁</button>
        <button data-value="3">≥60岁</button>
      </div>

      <!-- 问题2：疼痛性质 -->
      <div class="question">
        <h3>您的疼痛像哪种感觉？（可多选）</h3>
        <button data-value="1" data-type="painType">🔥 灼烧感</button>
        <button data-value="2" data-type="painType">⚡ 电击痛</button>
        <button data-value="1" data-type="painType">🔪 刀割痛</button>
        <button data-value="1" data-type="painType">😣 麻木</button>
        <button data-value="4" data-type="painType">
          ⚠️ 痛觉超敏（轻触诱发剧痛）
        </button>
      </div>

      <!-- 问题3：疼痛强度 -->
      <div class="question">
        <h3>您的疼痛强度是？（0分不痛，10分最痛）</h3>
        <input type="range" min="0" max="10" value="0" id="painIntensity" />
        <div><span id="intensity-value">0</span> 分</div>
      </div>

      <!-- 问题4：皮疹状态 -->
      <div class="question">
        <h3>您当前的皮疹状态？</h3>
        <button data-value="0">无皮疹</button>
        <button data-value="1">有水疱</button>
        <button data-value="1">结痂中</button>
        <button data-value="2">已愈合</button>
      </div>

      <!-- 问题5：基础疾病 -->
      <div class="question">
        <h3>您是否有以下疾病？（可多选）</h3>
        <button data-value="1" data-type="disease">糖尿病</button>
        <button data-value="2" data-type="disease">癌症</button>
        <button data-value="1" data-type="disease">肾病</button>
        <button data-value="0" data-type="disease">无</button>
      </div>

      <!-- 提交按钮 -->
      <button id="generate-report">查看我的风险等级</button>
    </div>

    <!-- 报告显示区域 -->
    <div id="report"></div>

    <script>
      // 初始化变量
      let userAnswers = {
        age: null,
        painType: 0, // 疼痛性质（取最高分）
        painIntensity: 0,
        rash: null,
        disease: 0,
      };

      // 1. 年龄选择（单选）
      document
        .querySelectorAll("[data-value]:not([data-type])")
        .forEach((button) => {
          button.addEventListener("click", function () {
            // 清除同组按钮选中状态
            this.parentNode
              .querySelectorAll("button")
              .forEach((btn) => (btn.style.backgroundColor = ""));
            // 设置当前按钮选中
            this.style.backgroundColor = "#e0e0e0";
            userAnswers.age = parseInt(this.getAttribute("data-value"));
          });
        });

      // 2. 疼痛性质（多选，取最高分）
      document.querySelectorAll('[data-type="painType"]').forEach((button) => {
        button.addEventListener("click", function () {
          this.style.backgroundColor =
            this.style.backgroundColor === "rgb(224, 224, 224)"
              ? ""
              : "#e0e0e0";
          const score = parseInt(this.getAttribute("data-value"));
          // 如果当前点击项分数更高，则更新
          if (
            this.style.backgroundColor === "rgb(224, 224, 224)" &&
            score > userAnswers.painType
          ) {
            userAnswers.painType = score;
          } else if (this.style.backgroundColor !== "rgb(224, 224, 224)") {
            // 如果取消选中，需要重新计算最高分
            userAnswers.painType = 0;
            document
              .querySelectorAll(
                '[data-type="painType"][style*="background-color: rgb(224, 224, 224)"]'
              )
              .forEach((btn) => {
                const s = parseInt(btn.getAttribute("data-value"));
                if (s > userAnswers.painType) userAnswers.painType = s;
              });
          }
        });
      });

      // 3. 疼痛强度（滑动条）
      const painSlider = document.getElementById("painIntensity");
      const intensityValue = document.getElementById("intensity-value");
      painSlider.addEventListener("input", function () {
        intensityValue.textContent = this.value;
        userAnswers.painIntensity = parseInt(this.value);
      });

      // 4. 皮疹状态（单选）
      document.querySelectorAll("[data-value]").forEach((button) => {
        if (
          button.parentNode.querySelector("h3").textContent.includes("皮疹状态")
        ) {
          button.addEventListener("click", function () {
            this.parentNode
              .querySelectorAll("button")
              .forEach((btn) => (btn.style.backgroundColor = ""));
            this.style.backgroundColor = "#e0e0e0";
            userAnswers.rash = parseInt(this.getAttribute("data-value"));
          });
        }
      });

      // 5. 基础疾病（多选，分数累加）
      document.querySelectorAll('[data-type="disease"]').forEach((button) => {
        button.addEventListener("click", function () {
          this.style.backgroundColor =
            this.style.backgroundColor === "rgb(224, 224, 224)"
              ? ""
              : "#e0e0e0";
          const score = parseInt(this.getAttribute("data-value"));
          if (this.style.backgroundColor === "rgb(224, 224, 224)") {
            userAnswers.disease += score;
          } else {
            userAnswers.disease -= score;
          }
        });
      });

      // 生成报告
      document
        .getElementById("generate-report")
        .addEventListener("click", function () {
          // 验证是否完成所有问题
          if (userAnswers.age === null || userAnswers.rash === null) {
            alert("请完成所有必答题！");
            return;
          }

          // 计算总分
          const score =
            userAnswers.age +
            userAnswers.painType +
            Math.floor(userAnswers.painIntensity / 3) + // 每3分计1分
            userAnswers.rash +
            userAnswers.disease;

          // 风险分级
          let riskLevel, riskClass, advice;
          if (score <= 3) {
            riskLevel = "低风险";
            riskClass = "risk-low";
            advice =
              "您的后遗神经痛风险较低（＜10%），建议观察疼痛变化，若2周未愈请就医，日常补充维生素B₁/B₁₂。";
          } else if (score <= 7) {
            riskLevel = "中风险";
            riskClass = "risk-medium";
            advice =
              "您的后遗神经痛风险中等（30-50%），请48小时内前往皮肤科就诊，并记录疼痛日记（频率、强度、诱因）。";
          } else {
            riskLevel = "高风险";
            riskClass = "risk-high";
            advice =
              "⚠️ 您的后遗神经痛风险很高（＞70%）！建议立即就医，72小时内抗病毒治疗可降低50%风险，避免抓挠皮疹。";
          }

          // 生成报告
          const reportDiv = document.getElementById("report");
          reportDiv.className = riskClass;
          reportDiv.style.display = "block";
          reportDiv.innerHTML = `
                <h2>您的神经痛风险等级：${riskLevel}</h2>
                <p><strong>评分详情</strong>：${score}分（满分14分）</p >
                <p><strong>主要风险因素</strong>：</p >
                <ul>
                    <li>年龄：${userAnswers.age}分</li>
                    <li>疼痛性质：${userAnswers.painType}分</li>
                    <li>疼痛强度：${Math.floor(
                      userAnswers.painIntensity / 3
                    )}分</li>
                    <li>皮疹状态：${userAnswers.rash}分</li>
                    <li>基础疾病：${userAnswers.disease}分</li>
                </ul>
                <p><strong>行动建议</strong>：${advice}</p >
                <p><small>注：本测试仅供参考，不作临床诊断依据。如有疑问请咨询医生。</small></p >
            `;
        });
    </script>
  </body>
</html>
